package com.zk.mockito.settings;

import com.zk.mockito.cases.Mocked;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.MockSettings;
import org.mockito.Mockito;
import org.mockito.internal.creation.MockSettingsImpl;

/**
 * Mock 多个接口，用于代码中出现类型强制转换场景
 */
public class MockSettingsOtherInterfaces {

    /**
     * 为Mock对象额外增加接口，该方法在代码中出现强制转换时使用
     */
    @Test
    public void addOtherInterfaces() {
        MockSettings settings = new MockSettingsImpl<>();
        settings.extraInterfaces(Comparable.class);
        Mocked mocked = Mockito.mock(Mocked.class, settings);
        Assert.assertTrue(mocked instanceof Comparable); // 此处为真
        if (mocked instanceof Comparable) {
            Comparable comparable = (Comparable) mocked;
            System.out.println(comparable.getClass());
        }
    }
}
